home *** CD-ROM | disk | FTP | other *** search
- /*
- sc_draw_packets.c - draw the packet window
- */
- #include "sc.h"
- #include "sc_packet_window.h"
- #include "sc_seer_globals.h"
- #include "pdl_data.h"
- #include "OUT.h"
-
- #define MAX_PAKS_PER_WINDOW 40 /*maximum number of displayed packets*/
-
- /*
- pak_height record of how many pixels high each packet is.
- indexed by draw_packet_num (including the trailing white space).
-
- <0 if height is unknown
- */
- static int pak_height[MAX_PAKS_PER_WINDOW+1];
- static int numb_paks; /*current number of displayed packets*/
-
- /* packets have been flushed from the queue, update the packet display*/
- void new_pak_display()
- {GrafPtr save_port;
- if(gl.wdf_packet==0)
- return;
- GetPort(&save_port); /*save the old graf port*/
- SetPort(gl.wdf_packet); /*switch to the port to update*/
- PAK_wdf->draw_packet_num=0;
- PAK_wdf->draw_pak_max= -1;
- inval_pak_cache();
- InvalRect(&gl.wdf_packet->windat.port.portRect);
- /* SetCtlValue crashes the system if control is not active */
- if(FrontWindow() == &gl.wdf_packet->windat.port)
- SetCtlValue(PAK_wdf->ctls[vscroll_ctl],0);
- SetPort(save_port);
- }
-
- /*inval_pak_cache - the window was scrolled backwards or something
- like that so don't depend on the previously displayed text being valid
- */
- void inval_pak_cache()
- {numb_paks=0;
- }
-
- /*print a line that text_pak made up*/
- void draw_flush(char*,int);
- void draw_flush(str,siz)
- register char *str;
- int siz;
- {if(siz!=0)
- DrawText(str,0,siz);
- MoveTo(gl.cur_windef->char_left_inset,
- CUR_WINDOW->pnLoc.v+gl.cur_windef->char_height);
- }
- /*
- draw_1_pak - draw the selected packet. return true if it doesn't
- exist
- */
- int draw_1_pak(int);
- static int draw_1_pak(sel_pak)
- int sel_pak;
- {int this_pak_size;
- long the_packet_num;
-
- /*might this packet be valid already?*/
- if(sel_pak<numb_paks) /*yes, it was printed before*/
- if((this_pak_size=pak_height[sel_pak])>=0) {/*is it valid on the screen now?*/
- /*yes, wonderful the screen is already ok*/
- /*move the pen to where it would have gone if we had needed to*/
- /*draw this packet*/
- MoveTo(gl.cur_windef->char_left_inset,this_pak_size);
- return false; /*the packet existed*/
- }
-
- /* don't select packets out of range */
- the_packet_num=PAK_wdf->draw_packet_num+sel_pak;
- if(the_packet_num>PAK_wdf->draw_pak_max)
- return true;
- if(text_pak(sp_status->pre_pak_num+1+the_packet_num))
- return true; /* no such packet */
- MoveTo(gl.cur_windef->char_left_inset,CUR_WINDOW->pnLoc.v+
- (gl.cur_windef->char_height/2));
-
- numb_paks=max(numb_paks,sel_pak+1); /*say how many valid paks on screen*/
- pak_height[sel_pak]=CUR_WINDOW->pnLoc.v;
-
- return false; /*say we had a packet, don't quit yet*/
- }
-
- /*
- display packets begining with draw_packet_num onto gl.cur_windef->windat
- for as many as will fit
- */
- void draw_packets(void);
- void draw_packets()
- {int scn_pak;
- char data_buffer[OUT_BUF_SIZE];
- out_start=data_buffer; /* buffer lines here*/
- out_stop=out_start+PAK_wdf->draw_pak_width;
- out_flush=draw_flush;
-
- /*start drawing here*/
- MoveTo(PAK_wdf->draw_pak_rect.left+gl.cur_windef->char_left_inset,
- PAK_wdf->draw_pak_rect.top+
- gl.cur_windef->char_height-
- gl.cur_windef->char_descent);
-
- for(scn_pak=0; /*display packets after draw_packet*/
- scn_pak<MAX_PAKS_PER_WINDOW;
- scn_pak++) {
- if(draw_1_pak(scn_pak)) { /*draw the current packet*/
- Move(gl.cur_windef->char_left_inset,0);
- DrawString("\p*** end of packet buffer ***");
- break;}
-
- /*see if anything after the current y display location might be visible*/
- /*off the end of the window?*/
- if(CUR_WINDOW->pnLoc.v >= PAK_wdf->draw_pak_rect.bottom) {
- numb_paks=max(0,numb_paks-1); /* last packet not compleatly drawn */
- break; /*yes, nothing else will be visible, so don't draw it*/
- } /* end if ran off the end */
- } /* end for scn_pak */
- }
-
- /*process an update event*/
- void e_pak_update_event()
- {show_grow();
- RectRgn(CUR_WINDOW->clipRgn,&PAK_wdf->draw_pak_rect);
- numb_paks=0;
- draw_packets(); /*draw needed parts of the packet window*/
- RectRgn(CUR_WINDOW->clipRgn,&CUR_WINDOW->portRect);
- }
-
- /*
- see if there is valid information on the screen that can be scrolled
- into place and save on redrawing, invalidate areas needing to
- be redrawn
- */
- void scroll_n_inval(long);
- void scroll_n_inval(pak_dist)
- long pak_dist;
- {register int vdist;
- register int i;
- RgnHandle bad_rgn;
- if(pak_dist==0) /* no jump, cache is fine */
- return;
- if((pak_dist<0)|| /* jump backwards, forget it */
- (pak_dist>=numb_paks)) {
- numb_paks=0;
- InvalRect(&PAK_wdf->draw_pak_rect);
- return;
- }
-
- vdist= (pak_height[pak_dist-1]+
- gl.cur_windef->char_descent-gl.cur_windef->char_height);
-
- bad_rgn=NewRgn();
- ScrollRect(&PAK_wdf->draw_pak_rect,
- 0,
- - vdist,
- bad_rgn);
- InvalRgn(bad_rgn);
- DisposeRgn(bad_rgn);
-
- numb_paks -= pak_dist;
- for(i=0;i<numb_paks;i++)
- pak_height[i] = pak_height[i+pak_dist] - vdist;
- return;
- }
-
- /*
- see if there is valid information on the screen that can be scrolled
- into place and save on redrawing
- */
- void scroll_draw_packets(pak_dist)
- long pak_dist;
- {scroll_n_inval(pak_dist); /*invalidate any areas needing updating */
- BeginUpdate(CUR_WINDOW);
- EraseRect(&CUR_WINDOW->portRect); /*yes, clear the update area*/
- draw_packets();
- EndUpdate(CUR_WINDOW);
- }
-
-